package com.douwong.student.utils;

import android.content.Context;
import android.media.MediaPlayer;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;

import com.douwong.student.R;
import com.douwong.student.contant.Config;


/**
 * 公用飞机提交
 * @author leihuajie
 *
 */
public class CommonPlaneCommit {
	private ScaleAnimation myAnimation_Scale;// 移动动画
	private AnimationSet animationSet;
	private TranslateAnimation myAnimation_Translate;// 缩放动画
	private ImageView plane_img;
	private int width,height;
	private MediaPlayer player;
	private Context context;
	public CommonPlaneCommit(Context context, ImageView plane_img, int width, int height){
		this.plane_img=plane_img;
		this.width=width;
		this.height=height;
		this.context=context;
	}
	public AnimationSet getAnimationSet(){
		myAnimation_Scale = new ScaleAnimation(1.0f, // 动画起始时 X坐标上的伸缩尺寸

				0.0f,// 动画结束时 X坐标上的伸缩尺寸

				1.0f, // 动画起始时Y坐标上的伸缩尺寸

				0.0f,// 动画结束时Y坐标上的伸缩尺寸

				Animation.RELATIVE_TO_SELF,//

				0.5f,// 动画相对于物件的X坐标的开始位置

				Animation.RELATIVE_TO_SELF, //

				1.0f);// 动画相对于物件的Y坐标的开始位置

		myAnimation_Scale.setFillAfter(false);

		myAnimation_Scale.setDuration(3000);

		// 缩放

		myAnimation_Translate = new TranslateAnimation(400f,// 动画起始时 X坐标上的位置

				-width - 400f,// 画结束时 X坐标上的位置

				400f,// 动画起始时 Y坐标上的位置

				(-(height+400)));// 动画结束时 Y坐标上的位置

		myAnimation_Translate.setFillAfter(false);

		myAnimation_Translate.setDuration(3000);

		animationSet = new AnimationSet(true);
		myAnimation_Translate.setInterpolator(new AccelerateInterpolator());
		animationSet.addAnimation(myAnimation_Scale);

		animationSet.addAnimation(myAnimation_Translate);

		animationSet.setAnimationListener(new AnimationListener() {

			@Override
			public void onAnimationStart(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationRepeat(Animation animation) {
				// TODO Auto-generated method stub

			}

			@Override
			public void onAnimationEnd(Animation animation) {
				// TODO Auto-generated method stub
				plane_img.setVisibility(View.INVISIBLE);
			}
		});
		if(PreferencesUtils.getInstance().getBoolean(Config.IS_ROUND,true)){
			player= MediaPlayer.create(context, R.raw.plane_sound);
			player.start();
		}
		return animationSet;
	}
	// 移动

			
}
